package com.easylinkin.linkappapi.security.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import site.morn.data.Displayable;
import site.morn.data.Lockable;
import site.morn.framework.entity.BaseUser;
import site.morn.validate.group.Add;
import site.morn.validate.group.Login;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 用户实体类
 *
 * @author 
 * @since 1.0.0, 2019/8/13
 */
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@FieldNameConstants
@TableName("linkapp_user")
@Table(name = "linkapp_user")
@ApiModel("用户实体类")
@EqualsAndHashCode(callSuper = true)
public class LinkappUser extends BaseUser implements Displayable, Lockable {

  /**
   * @serialField
   */
  private static final long serialVersionUID = 1L;
  
  /**
   * 用户名
   */
  @ApiModelProperty("用户名")
  @NotNull(groups = {Add.class, Login.class})
  private String username;

  @ApiModelProperty("显示状态")
  @Column
  private Boolean display;

  @ApiModelProperty("锁定状态")
  @Column
  private Boolean locked;

  /**
   * 1.管理员 2.普通用户
   */
  @ApiModelProperty("用户类型")
  @Column(name="type")
  private String type;
  
  @Column(name="index_config_url")
  private String indexConfigUrl;
  
  @Column(name="index_config_code")
  private String indexConfigCode;

  @ApiModelProperty("所属角色")
  @ManyToMany
  @ToString.Exclude
  @TableField(exist = false)
  @EqualsAndHashCode.Exclude
  @JoinTable(name = "linkapp_user_ref_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
  private List<LinkappRole> roles;
  
  @Column(name="tenant_id")
  private String tenantId;

  /**
   * 是否显示大屏图标
   */
  @Column(name="is_show_screen")
  private Integer isShowScreen;
  
  @TableField(exist = false)
  @Transient
  private String verificationCode;


  /**
   * username模糊查询条件
   */
  @TableField(exist = false)
  @Transient
  private String usernameLikeQuery;

  /**
   * 极光推送平台对应的id
   */
  @Column(name="registration_id")
  private String registrationId;
  
}
